home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / SLBitmap.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  15.8 KB  |  548 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLBitmap.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLPALETE_H
  13. #include "SLPalete.h"
  14. #endif
  15.  
  16. #ifndef SLBITMAP_H
  17. #include "SLBitmap.h"
  18. #endif
  19.  
  20. #ifndef PRBITMAP_H
  21. #include "PRBitmap.h"
  22. #endif
  23.  
  24. #ifndef PRPICTUR_H
  25. #include "PRPictur.h"
  26. #endif
  27.  
  28. #ifndef FWODEXCE_H
  29. #include "FWODExce.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. #ifndef FWCOLOR_H
  37. #include "FWColor.h"
  38. #endif
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment FWGraphics_Bitmap
  42. #endif
  43.  
  44. //----------------------------------------------------------------------------------------
  45. //    FW_PrivBitmap_CreateFromBits
  46. //----------------------------------------------------------------------------------------
  47.  
  48. FW_HBitmap SL_API FW_PrivBitmap_CreateFromBits(
  49.                                 short width, short height, short pixelSize, FW_Palette palette,
  50.                                 void* image, long imageSize, short rowBytes,
  51.                                 FW_PlatformError* error)
  52. {
  53.     FW_ERR_TRY
  54.     {
  55.         return FW_NEW(FW_CPrivBitmapRep, (width, height, pixelSize, palette, image, imageSize, rowBytes));
  56.     }
  57.     FW_ERR_CATCH
  58.     return 0;    
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------
  62. //    FW_PrivBitmap_CreateFromPlatformBitmap
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_HBitmap SL_API FW_PrivBitmap_CreateFromPlatformBitmap(
  66.                                 FW_PlatformBitmap platformBitmap,
  67.                                 FW_PlatformError* error)
  68. {
  69.     FW_ERR_TRY
  70.     {
  71.         return FW_NEW(FW_CPrivBitmapRep, (platformBitmap));
  72.     }
  73.     FW_ERR_CATCH
  74.     return 0;    
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_PrivBitmap_CreateFromResource
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_HBitmap SL_API FW_PrivBitmap_CreateFromResource(
  82.                                 FW_OResourceFile* resourceFile,
  83.                                 FW_ResourceID resID,
  84.                                 FW_PlatformError* error)
  85. {
  86.     FW_ERR_TRY
  87.     {
  88.         return FW_NEW(FW_CPrivBitmapRep, (resourceFile, resID));
  89.     }
  90.     FW_ERR_CATCH
  91.     return 0;    
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_PrivBitmap_Copy
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_HBitmap SL_API FW_PrivBitmap_Copy(FW_HBitmap bitmap, const FW_SRect& srcRect, FW_PlatformError* error)
  99. {
  100.     FW_ASSERT(bitmap);
  101.     
  102.     FW_ERR_TRY
  103.     {
  104.         return FW_NEW(FW_CPrivBitmapRep, (*bitmap, srcRect));
  105.     }
  106.     FW_ERR_CATCH
  107.     return 0;    
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_PrivBitmap_IsEqual
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_Boolean SL_API FW_PrivBitmap_IsEqual(FW_HBitmap bitmap, FW_HBitmap bitmap2)
  115. {
  116.     FW_ASSERT(bitmap);
  117.     FW_ASSERT(bitmap2);
  118.  
  119.     // No try block necessary - Do not throw
  120.     return bitmap->IsEqual(*bitmap2);
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_PrivBitmap_Read
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_HBitmap SL_API FW_PrivBitmap_Read(
  128.                                 FW_HReadableStream    hStream,
  129.                                 FW_Boolean             bDIBFileHeader,
  130.                                 FW_PlatformError*     error)
  131. {
  132.     FW_ERR_TRY
  133.     {
  134.         FW_CReadableStream stream(hStream);
  135.         return FW_NEW(FW_CPrivBitmapRep, (stream, bDIBFileHeader));
  136.     }
  137.     FW_ERR_CATCH
  138.     return 0;    
  139. }
  140.     
  141. //----------------------------------------------------------------------------------------
  142. //    FW_PrivBitmap_Write
  143. //----------------------------------------------------------------------------------------
  144.  
  145. void SL_API FW_PrivBitmap_Write(
  146.                                 FW_HBitmap             bitmap,
  147.                                 FW_HWritableStream    hStream,
  148.                                 FW_Boolean             bDIBFileHeader,
  149.                                 FW_PlatformError*    error)
  150. {
  151.     FW_ASSERT(bitmap);
  152.  
  153.     FW_ERR_TRY
  154.     {
  155.         FW_CWritableStream stream(hStream);
  156.         bitmap->Write(stream, bDIBFileHeader);
  157.     }
  158.     FW_ERR_CATCH
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_PrivBitmap_Acquire
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void SL_API FW_PrivBitmap_Acquire(FW_HBitmap bitmap)
  166. {
  167.     FW_ASSERT(bitmap);
  168.  
  169.     // No try block necessary - Do not throw
  170.     bitmap->Acquire();
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_PrivBitmap_GetRefCount
  175. //----------------------------------------------------------------------------------------
  176.  
  177. long SL_API FW_PrivBitmap_GetRefCount(FW_HBitmap bitmap)
  178. {
  179.     FW_ASSERT(bitmap);
  180.  
  181.     // No try block necessary - Do not throw
  182.     return bitmap->GetRefCount();
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_PrivBitmap_Release
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void SL_API FW_PrivBitmap_Release(FW_HBitmap bitmap)
  190. {
  191.     FW_ASSERT(bitmap);
  192.  
  193.     // No try block necessary - Do not throw
  194.     bitmap->Release();
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_PrivBitmap_GetPlatformBitmap
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_PlatformBitmap SL_API FW_PrivBitmap_GetPlatformBitmap(FW_HBitmap bitmap)
  202. {
  203.     FW_ASSERT(bitmap);
  204.  
  205.     // No try block necessary - Do not throw
  206.     return bitmap->GetPlatformBitmap();
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_PrivBitmap_IsPlatformBitmapOrphan
  211. //----------------------------------------------------------------------------------------
  212.  
  213. FW_Boolean SL_API FW_PrivBitmap_IsPlatformBitmapOrphan(FW_HBitmap bitmap)
  214. {
  215.     FW_ASSERT(bitmap);
  216.  
  217.     // No try block necessary - Do not throw
  218.     return bitmap->IsPlatformBitmapOrphan();
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_PrivBitmap_OrphanPlatformBitmap
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_PlatformBitmap SL_API FW_PrivBitmap_OrphanPlatformBitmap(FW_HBitmap bitmap)
  226. {
  227.     FW_ASSERT(bitmap);
  228.  
  229.     // No try block necessary - Do not throw
  230.     return bitmap->OrphanPlatformBitmap();
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_PrivBitmap_SetPlatformBitmap
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_PlatformError SL_API FW_PrivBitmap_SetPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  238. {
  239.     FW_ASSERT(bitmap);
  240.  
  241.     // No try block necessary - Do not throw
  242.     bitmap->SetPlatformBitmap(newBitmap);
  243.     return FW_xNoError;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_PrivBitmap_AdoptPlatformBitmap
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_PlatformError SL_API FW_PrivBitmap_AdoptPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  251. {
  252.     FW_ASSERT(bitmap);
  253.  
  254.     // No try block necessary - Do not throw
  255.     bitmap->AdoptPlatformBitmap(newBitmap);
  256.     return FW_xNoError;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_PrivBitmap_GetPalette
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_Palette SL_API FW_PrivBitmap_GetPalette(FW_HBitmap bitmap, FW_PlatformError* error)
  264. {
  265.     FW_ASSERT(bitmap);
  266.  
  267.     FW_ERR_TRY
  268.     {
  269.         return bitmap->GetPalette();
  270.     }
  271.     FW_ERR_CATCH
  272.     return NULL;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_PrivBitmap_SetPalette
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_PlatformError SL_API FW_PrivBitmap_SetPalette(FW_HBitmap bitmap, FW_Palette palette)
  280. {
  281.     FW_ASSERT(bitmap);
  282.  
  283.     FW_RETURN_ERR_TRY
  284.     {
  285.         bitmap->SetPalette(palette);
  286.     }
  287.     FW_RETURN_ERR_CATCH
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. //    FW_PrivBitmap_GetBitmapInfo
  292. //----------------------------------------------------------------------------------------
  293.  
  294. FW_PlatformError SL_API FW_PrivBitmap_GetBitmapInfo(
  295.                                 FW_HBitmap     bitmap,
  296.                                 short&        width,
  297.                                 short&        height, 
  298.                                 short&        rowBytes,
  299.                                 short&        pixelSize)
  300. {
  301.     FW_ASSERT(bitmap);
  302.  
  303.     // No try block necessary - Do not throw
  304.     bitmap->GetBitmapInfo(width, height, rowBytes, pixelSize);
  305.     return FW_xNoError;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_PrivBitmap_GetBitmapBoundsGC
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void SL_API FW_PrivBitmap_GetBitmapBoundsGC(Environment* ev, FW_HBitmap bitmap, FW_SGraphicContext& gc, FW_SRect& bounds)
  313. {
  314.     FW_ASSERT(bitmap);
  315.  
  316.     // No try block necessary - Do not throw
  317.     bitmap->GetBitmapBoundsGC(ev, gc, bounds);
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. //    FW_PrivBitmap_GetBitmapBounds
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void SL_API FW_PrivBitmap_GetBitmapBounds(FW_HBitmap bitmap, FW_SRect& bounds)
  325. {
  326.     FW_ASSERT(bitmap);
  327.  
  328.     bitmap->GetBitmapBounds(bounds);
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    FW_PrivBitmap_GetPixelColor
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void SL_API    FW_PrivBitmap_GetPixelColor(FW_HBitmap bitmap,
  336.                                         short horiz, 
  337.                                         short vert, 
  338.                                         FW_SColor& color)
  339. {
  340.     FW_ASSERT(bitmap);
  341.     
  342.     FW_CColor pixelColor;
  343.     bitmap->GetPixelColor(horiz, vert, pixelColor);
  344.     color = pixelColor;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_PrivBitmap_SetPixelColor
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void SL_API FW_PrivBitmap_SetPixelColor(FW_HBitmap bitmap,
  352.                                         short horiz,
  353.                                         short vert,
  354.                                         const FW_SColor& color)
  355. {
  356.     FW_ASSERT(bitmap);
  357.     
  358.     bitmap->SetPixelColor(horiz, vert, color);
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. //    FW_PrivBitmap_ChangeBitmap
  363. //----------------------------------------------------------------------------------------
  364.  
  365. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmap(FW_HBitmap     bitmap,
  366.                                         void*        image,
  367.                                         long        imageSize,
  368.                                         short        rowBytes,
  369.                                         short        width,
  370.                                         short        height, 
  371.                                         short        pixelSize,
  372.                                         FW_Boolean    bScale)
  373. {
  374.     FW_UNUSED(bScale);
  375.     FW_ASSERT(bitmap);
  376.  
  377.     // No try block necessary - Do not throw
  378.     return bitmap->ChangeBitmap(image, imageSize, rowBytes, width, height, pixelSize, NULL);
  379. }
  380.  
  381. //----------------------------------------------------------------------------------------
  382. //    FW_PrivBitmap_ChangeImageAndPalette
  383. //----------------------------------------------------------------------------------------
  384.  
  385. FW_PlatformError SL_API FW_PrivBitmap_ChangeImageAndPalette(FW_HBitmap     bitmap,
  386.                                         void*        image,
  387.                                         long        imageSize,
  388.                                         short        rowBytes,
  389.                                         short        width,
  390.                                         short        height, 
  391.                                         short        pixelSize,
  392.                                         FW_Palette    palette)
  393. {
  394.     FW_ASSERT(bitmap);
  395.  
  396.     // No try block necessary - Do not throw
  397.     return bitmap->ChangeBitmap(image, imageSize, rowBytes, width, height, pixelSize, palette);
  398. }
  399.  
  400. //----------------------------------------------------------------------------------------
  401. //    FW_PrivBitmap_ChangeGeometryAndPalette
  402. //----------------------------------------------------------------------------------------
  403.  
  404. FW_PlatformError    SL_API FW_PrivBitmap_ChangeGeometryAndPalette(FW_HBitmap     bitmap,
  405.                                 short        width,
  406.                                 short        height, 
  407.                                 short        pixelSize,
  408.                                 FW_Boolean    bScale,
  409.                                 FW_Palette  palette)
  410. {
  411.     FW_ASSERT(bitmap);
  412.  
  413.     // No try block necessary - Do not throw
  414.     return bitmap->ChangeBitmap(width, height, pixelSize, bScale, palette);
  415. }
  416.                             
  417. //----------------------------------------------------------------------------------------
  418. //    FW_PrivBitmap_ChangeBitmapGeometry
  419. //----------------------------------------------------------------------------------------
  420.  
  421. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmapGeometry(FW_HBitmap     bitmap,
  422.                                                 short        width,
  423.                                                 short        height, 
  424.                                                 short        pixelSize,
  425.                                                 FW_Boolean    bScale)
  426. {
  427.     FW_ASSERT(bitmap);
  428.  
  429.     // No try block necessary - Do not throw
  430.     return bitmap->ChangeBitmap(width, height, pixelSize, bScale, NULL);
  431. }
  432.                                     
  433. //----------------------------------------------------------------------------------------
  434. //    FW_PrivBitmap_SetImage
  435. //----------------------------------------------------------------------------------------
  436.  
  437. FW_PlatformError SL_API FW_PrivBitmap_SetImage(FW_HBitmap bitmap, 
  438.                                 void* image, 
  439.                                 long imageSize, 
  440.                                 short rowBytes)
  441. {
  442.     FW_ASSERT(bitmap);
  443.  
  444.     // No try block necessary - Do not throw
  445.     return bitmap->SetImage(image, imageSize, rowBytes);
  446. }
  447.  
  448. //----------------------------------------------------------------------------------------
  449. //    FW_PrivBitmap_CopyPixels
  450. //----------------------------------------------------------------------------------------
  451.  
  452. FW_PlatformError SL_API FW_PrivBitmap_CopyPixels(
  453.                                 FW_HBitmap    bitmapSrc, 
  454.                                 FW_HBitmap    bitmapDst,
  455.                                 FW_SRect&     boundsSrc, 
  456.                                 FW_SRect&    boundsDst)
  457. {
  458.     FW_ASSERT(bitmapSrc);
  459.     FW_ASSERT(bitmapDst);
  460.  
  461.     // No try block necessary - Do not throw
  462.     return bitmapSrc->CopyPixels(*bitmapDst, boundsSrc, boundsDst);
  463. }
  464.  
  465. #ifdef FW_BUILD_MAC
  466. //----------------------------------------------------------------------------------------
  467. //    FW_PrivBitmap_MacCreateFromPicture
  468. //----------------------------------------------------------------------------------------
  469.  
  470. FW_HBitmap SL_API FW_PrivBitmap_MacCreateFromPicture(
  471.                                 FW_HPicture picture, FW_SColor fillColor,
  472.                                 const FW_SRect& pictPart, FW_PlatformError* error)
  473. {
  474.     FW_ASSERT(picture);
  475.  
  476.     FW_ERR_TRY
  477.     {
  478.         return FW_NEW(FW_CPrivBitmapRep, (picture, fillColor, pictPart));
  479.     }
  480.     FW_ERR_CATCH
  481.     return NULL;
  482. }
  483. #endif
  484.  
  485. #ifdef FW_BUILD_MAC
  486. //----------------------------------------------------------------------------------------
  487. //    FW_PrivBitmap_MacGetAsPicture
  488. //----------------------------------------------------------------------------------------
  489.  
  490. FW_HPicture SL_API FW_PrivBitmap_MacGetAsPicture(FW_HBitmap bitmap, 
  491.                                                 const FW_SRect& bounds, 
  492.                                                 FW_PlatformError* error)
  493. {
  494.     FW_ASSERT(bitmap);
  495.  
  496.     FW_ERR_TRY
  497.     {
  498.         return bitmap->MacGetAsPicture(bounds);
  499.     }
  500.     FW_ERR_CATCH
  501.     return 0;
  502. }
  503. #endif
  504.  
  505. #ifdef FW_BUILD_MAC
  506. //----------------------------------------------------------------------------------------
  507. //    FW_PrivBitmap_MacLockPixels
  508. //----------------------------------------------------------------------------------------
  509.  
  510. PixMapHandle SL_API FW_PrivBitmap_MacLockPixels(FW_HBitmap bitmap)
  511. {
  512.     FW_ASSERT(bitmap);
  513.  
  514.     // No try block necessary - Do not throw
  515.     return bitmap->MacLockPixels();    // return NULL if fails
  516. }
  517. #endif
  518.  
  519. #ifdef FW_BUILD_MAC
  520. //----------------------------------------------------------------------------------------
  521. //    FW_PrivBitmap_MacUnlockPixels
  522. //----------------------------------------------------------------------------------------
  523.  
  524. FW_PlatformError SL_API FW_PrivBitmap_MacUnlockPixels(FW_HBitmap bitmap)
  525. {
  526.     FW_ASSERT(bitmap);
  527.  
  528.     // No try block necessary - Do not throw
  529.     bitmap->MacUnlockPixels();
  530.     return FW_xNoError;
  531. }
  532. #endif
  533.  
  534. #ifdef FW_BUILD_MAC
  535. //----------------------------------------------------------------------------------------
  536. //    FW_PrivBitmap_MacIsPixelsLocked
  537. //----------------------------------------------------------------------------------------
  538.  
  539. FW_Boolean SL_API FW_PrivBitmap_MacIsPixelsLocked(FW_HBitmap bitmap)
  540. {
  541.     FW_ASSERT(bitmap);
  542.  
  543.     // No try block necessary - Do not throw
  544.     return bitmap->MacIsPixelsLocked();
  545. }
  546.  
  547. #endif
  548.